#include <iostream>
#include "test.h"
TurnClient* client;
bool isConnected = false;
int ukbps = 0;
int64_t lastts = 0, mb = 0;
void OnRecv(uint8_t* buffer, uint32_t len)
{
	ukbps += len;
	mb += len;
	test_recv(buffer, len);
}
void OnDisconnect()
{
	isConnected = false;
	client->Connect(123456, 5000);
	printf("-------------------- disconnect -------------------");
}
void OnConnectCompleted(bool connect)
{
	isConnected = connect;
	if (!connect)
		OnDisconnect();
	else
		lastts = RCTP::GetTimestamp();
}

void OnGetClients(std::vector<uint32_t> clients)
{

}

int main(int argc, char argv[])
{
	client = new TurnClient("127.0.0.1", 5555, 123456);
	client->RegisterRecvCallback(OnRecv);
	client->RegisterConnectCompleted(OnConnectCompleted);
	client->RegisterDisconnected(OnDisconnect);
	client->RegisterGetClients(OnGetClients);
	client->Connect(123456, 5000);
	while (true)
	{
		client->Update(0);
		if (isConnected)
		{
			test_send(client);
		}
		if (RCTP::GetTimestamp() - lastts > 1000)
		{
			lastts = RCTP::GetTimestamp();
			printf("rate: %d kbps\ttotal: %d mb\n", ukbps / 1000, mb / 1000000);
			ukbps = 0;
		}
	}
	client->Disconnect();
	delete client;
	return 0;
}